{{- $page := .page }}
{{- $class := .class | default "" }}
{{- $href := (trim .href " ") | default "" }}
{{- $onempty := cond (isset . "onempty") .onempty "disable" }}
{{- $onwidths := cond (isset . "onwidths") .onwidths "show" }}
{{- $onwidthm := cond (isset . "onwidthm") .onwidthm "show" }}
{{- $onwidthl := cond (isset . "onwidthl") .onwidthl "show" }}
{{- $attributes := .attributes | default dict }}
{{- $type := .type | default "" }}
{{- $title := (trim .title " ") | default "" }}
{{- $hint := (trim .hint " ") | default "" }}
{{- $icon := (trim .icon " ") | default "" }}
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
  {{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
{{- $content := .content }}
{{- $isDisabled := not $href }}
{{- $isButton := false }}
{{- if or (not $href) (strings.HasPrefix $href "javascript:") }}
  {{- $isButton = true }}
  {{- $href = substr $href (len "javascript:") }}
  {{- if not $type }}
    {{- $type = "button" }}
  {{- end }}
{{- else }}
  {{- $u := urls.Parse .href }}
  {{- if $u.IsAbs }}
    {{- partialCached "_relearn/urlExists.gotmpl" (dict "url" .href "page" $page "type" "link") $u.String }}
  {{- else }}
    {{- $linkObject := partial "_relearn/linkObject.gotmpl" (dict "url" .href "page" $page) }}
    {{- if $linkObject }}
      {{- $href = partial "_relearn/decoratedLink.gotmpl" (dict "url" .href "page" $page "linkObject" $linkObject "param" "link") }}
    {{- else }}
      {{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
      {{- $msg := printf "%q: link '%s' is not a page or a resource" $filepath .href }}
      {{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .href "page" $page "param" "link" "msg" $msg) }}
    {{- end }}
  {{- end }}
  {{- $attributes = merge $attributes (partial "_relearn/linkAttributes.gotmpl" (dict "url" $href "page" $page "attributes" (dict "class" "topbar-control" "title" $hint))) }}
{{- end }}
            <div class="topbar-button {{ $class }}" data-content-empty="{{ $onempty }}" data-width-s="{{ $onwidths }}" data-width-m="{{ $onwidthm }}" data-width-l="{{ $onwidthl }}">
{{- if $isDisabled -}}
              <span class="topbar-control">
{{- else if $isButton -}}
              <button class="topbar-control"{{ if $href }} onclick="{{ $href | safeJS }}"{{ end }}{{ if gt (len $type) 0 }} type="{{ $type }}"{{ end }} title="{{ $hint }}">
{{- else -}}
              <a
                {{- range $k, $v := $attributes }}
                  {{- if $v }}
                    {{- if eq (printf "%T" $v) "bool" }}
                      {{- printf " %s" $k | safeHTMLAttr }}
                    {{- else }}
                      {{- printf " %s=%q" $k $v | safeHTMLAttr }}
                    {{- end }}
                  {{- end }}
                {{- end }}>
{{- end }}
{{- if and $icon }}<i class="{{ $icon }}"></i>{{ end }}
{{- if and $icon $title }} {{ end }}
{{- if $title }}<span class="title">{{- $title | safeHTML }}</span>{{ end }}
{{- if $isDisabled -}}
              </span>
{{- else if $isButton -}}
              </button>
{{- else -}}
              </a>
{{- end }}
{{- if $content }}
              <div class="topbar-content">
                <div class="topbar-content-wrapper">
                  {{- $content }}
                </div>
              </div>
{{- end }}
            </div>